package com.fengye.algorithms.leecode.common;

import java.util.List;

/**
 * @Author fengye
 * @Date 2023/4/8 11:13
 **/
public class TreeNode {
    public int val;
    public TreeNode left;
    public TreeNode right;

    public TreeNode() {
    }

    public TreeNode(int val) {
        this.val = val;
    }

    public TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    public void print() {
        doPreDfs(this);
    }

    public void doPreDfs(TreeNode node) {
        if(node == null) {
            return;
        }
        System.out.print(node.val + " ");
        if(node.left != null) {
            doPreDfs(node.left);
        }

        if(node.right != null) {
            doPreDfs(node.right);
        }
    }
}
